package com.tomcov.client.activities;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.http.client.UrlBuilder;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.tomcov.client.ClientFactory;
import com.tomcov.client.view.I18nView;

// TODO: Auto-generated Javadoc
/**
 * The Class I18nActivity.
 */
public class I18nActivity extends AbstractActivity implements I18nView.Presenter{

        /** The client factory. */
        private ClientFactory clientFactory;

        
        /**
         * Instantiates a new i18n activity.
         *
         * @param clientFactory the client factory
         */
        public I18nActivity(ClientFactory clientFactory){
        this.clientFactory = clientFactory;     
        }
        
        /* (non-Javadoc)
         * @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget, com.google.gwt.event.shared.EventBus)
         */
        @Override
        public void start(AcceptsOneWidget panel, EventBus eventBus) {
                I18nView i18nView = clientFactory.getI18nView();
                i18nView.geten().addClickHandler(new ClickHandler(){
                        @Override
                        public void onClick(ClickEvent event) {
                                UrlBuilder url = Window.Location.createUrlBuilder().setParameter("locale", "en");
                                Window.Location.replace(url.buildString());
                        }
                });
                i18nView.getfr().addClickHandler(new ClickHandler(){
                        @Override
                        public void onClick(ClickEvent event) {
                                UrlBuilder url = Window.Location.createUrlBuilder().setParameter("locale", "fr");
                                Window.Location.replace(url.buildString());
                        }
                });
                i18nView.getnl().addClickHandler(new ClickHandler(){
                        @Override
                        public void onClick(ClickEvent event) {
                                UrlBuilder url = Window.Location.createUrlBuilder().setParameter("locale", "nl");
                                Window.Location.replace(url.buildString());
                        }
                });
                
                
                i18nView.setPresenter(this);
        panel.setWidget(i18nView.asWidget());

                
        }

        /* (non-Javadoc)
         * @see com.tomcov.client.view.I18nView.Presenter#goTo(com.google.gwt.place.shared.Place)
         */
        @Override
        public void goTo(Place place) {
                clientFactory.getPlaceController().goTo(place);         
        }

}
